home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java for 3D & VRML Worlds
/
Java for 3d and VRML Worlds.iso
/
vs
/
browser
/
cpb10ebx.exe
/
DATA.Z
/
exit.java
< prev
next >
Wrap
Text File
|
1996-09-25
|
3KB
|
117 lines
//
// exit.java
// ok, cancel button & load initial color
//
// (c) Copyright 1996 Sony Corporation. All rights reserved.
import vrml.*;
import vrml.field.*;
import vrml.node.*;
import vs.*;
public class exit extends Script {
final int PARTS_MAX = 18;
final int COLOR_MAX = 18;
SFColor diffuse[] = new SFColor[ PARTS_MAX ];
float f[] = new float[3] ;
final int cBase = '0';
public void processEvent(Event e){
if( ((ConstSFBool)e.getValue()).getValue() == true ){
String code = "";
// System.out.println ( e.getName() );
if(e.getName().equals("clicked_ok")){
String str;
// get colors
SFInt32 colorno[] = new SFInt32 [ PARTS_MAX ];
for( int i = 0; i < PARTS_MAX; i++ ){
str = "part" + i + "_colorNo";
colorno[ i ] = (SFInt32) getField( str );
// generating codes
code += (char)( colorno[i].getValue() + cBase );
// System.out.println ( colorno[ i ] );
}
// set registories
System.out.println ( "code saved: " + code );
Vscp.setAvtroomAvatarColor( code );
// go to previous world
Vscp.goFromAvtroomToOriginalWorld();
// getBrowser().setDescription ( "press Back button to return" );
}
if(e.getName().equals("clicked_ng")){
// get initial colors
// System.out.println ( "cancel" );
// restore colors
load();
}
if(e.getName().equals("init")){
// get initial colors
// System.out.println ( "initialize colors" );
// restore colors
load();
}
}
}
public void load ( ){
String colorString = Vscp.getAvtroomAvatarColor();
String str;
SFInt32 colorNo;
float f[] = new float[ 3 ];
int doll_no = 0;
String avtURL = Vscp.getAvtroomAvatarURL();
if( avtURL.endsWith( "boy.wrl" )){
doll_no = 0;
}
else if ( avtURL.endsWith( "girl.wrl" )){
doll_no = 1;
}
// System.out.println ( "initialize colors: " + doll_no );
// decode
if ( colorString.length() < PARTS_MAX ){
// set default color
for ( int i = 0; i < PARTS_MAX; i++ ){
f = GenerateColor.getDefaultColor( i, doll_no );
diffuse[ i ].setValue( f );
}
}
else{
for ( int i = 0; i < PARTS_MAX; i++ ){
int decode = (int) colorString.charAt( i ) - cBase;
// set colorNo
str = "part" + i + "_colorNo";
colorNo = (SFInt32) getField( str );
colorNo.setValue( decode );
// set diffuse color
if ( decode < COLOR_MAX ){
f = GenerateColor.getSFColor( decode );
diffuse[ i ].setValue( f );
}
else{ // set default color
f = GenerateColor.getDefaultColor( i, doll_no );
diffuse[ i ].setValue( f );
}
}
}
}
public void initialize (){
String str;
for( int i = 0; i < PARTS_MAX; i++ ){
str = "part" + i + "_color";
diffuse[ i ] = ( SFColor ) getEventOut( str ) ;
}
}
}